﻿using Engine;
using Engine.Graphics;
using Game;

namespace JackODummy
{
	public class JackODummyBlock : Block
	{
		readonly BlockMesh m_iconMesh = new();
		Texture2D m_texture;

		public override void Initialize()
		{
			m_texture = ContentManager.Get<Texture2D>("Textures/JackODummy");
			Model model = ContentManager.Get<Model>("Models/JackODummy");
			foreach (var mesh in model.Meshes)
			{
				bool doubleSide = mesh.Name == "Body" || mesh.Name == "Hat";
				Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(mesh.ParentBone) * Matrix.CreateScale(0.75f);
				Matrix matrix = Matrix.CreateRotationX(MathUtils.DegToRad(90f)) * boneAbsoluteTransform * Matrix.CreateRotationX(MathUtils.DegToRad(-90f));
				m_iconMesh.AppendModelMeshPart(mesh.MeshParts[0], matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: doubleSide, flipNormals: false, Color.White);
			}
			base.Initialize();
		}
		public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
		{
		}

		public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
		{
			BlocksManager.DrawMeshBlock(primitivesRenderer, m_iconMesh, m_texture, color, 2f * size, ref matrix, environmentData);
		}
	}
}